<!--
 * @Author: xiaotiwen
 * @Date: 2020-05-08 18:14:49
 * @LastEditTime: 2020-07-21 15:16:54
 * @LastEditors: xiaotiwen
 * @FilePath: \eduweb\src\views\practiceManagement\practiceReworkManagement\index.vue
 * @Description: 实践重修管理
 -->
<template>
    <div class="ReworkMana">
        <inner-breadcrumb v-model="pathKey" :path="path" />
        <div v-show="pathKey === 'main'">
            <ConditionCard shadow="never" label-width="120px" @search="onSubmit" @reset="reset">
                <el-row :gutter="24">
                    <el-col :span="8">
                        <el-form-item :label="$t('label.schoolTerm')">
                            <CalendarSelect v-model="queryForm.yearTerm" @load-done="loadDone" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item :label="$t('label.grade')">
                            <el-date-picker
                                v-model="queryForm.grade"
                                value-format="yyyy"
                                type="year"
                                :placeholder="$t('message.plzSelect')"
                                style="width: 100%"
                            />
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item :label="$t('fundingManagement.label.courseOpenAcademy')">
                            <DictSelect v-model="queryForm.collegeId" :data="options.collegeId" :clearable="false" :filterable="true"></DictSelect>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row :gutter="24">
                    <el-col :span="8">
                        <el-form-item :label="$t('courseConfirmation.label.stuFaculty')">
                            <DictSelect
                                v-model="queryForm.acdemyId"
                                :data="options.acdemyId"
                                :clearable="false"
                                :filterable="true"
                            />
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item :label="$t('label.major')">
                            <MyMajor
                                :faculty="queryForm.acdemyId"
                                :grade="queryForm.grade"
                                v-model="queryForm.majorId"
                            />
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item :label="$t('label.trainingLevel')">
                            <DictSelect
                                v-model="queryForm.trainingLevel"
                                :data="options.trainingLevel"
                                :clearable="false"
                                :disabled="true"
                            />
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row :gutter="24">
                    <el-col :span="8">
                        <el-form-item :label="$t('courseSummary.aduitType')">
                            <el-select v-model="queryForm.status" style="width: 100%" clearable>
                                <el-option
                                    v-for="(item, idx) in options.status"
                                    :key="idx"
                                    :value="item.value"
                                    :label="item.label"
                                />
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item :label="$t('fundingManagement.label.courseCode')">
                            <el-input
                                v-model="queryForm.courseId"
                                maxlength="20"
                                :placeholder="$t('fundingManagement.tips.plzInput')"
                            />
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item :label="$t('fundingManagement.label.courseName')">
                            <el-input
                                v-model="queryForm.courseName"
                                maxlength="20"
                                :placeholder="$t('fundingManagement.tips.plzInput')"
                            />
                        </el-form-item>
                    </el-col>
                </el-row>
            </ConditionCard>
            <el-card shadow="never" body-style="padding: 24px;">
                <div class="edu-opertion-bar">
                    <h2 class="titles">{{ $t('practiceReworkManagement.title.pageTitle') }}</h2>
                    <div class="float-left">
                      <KeywordInput v-if="!global.isStudent" v-model="queryForm.studentNameNum" :placeholder="$t('dispersionPracticeApply.tips.plzInputNameOrCode')" @enter="handSearchChang"></KeywordInput>
                        <!-- <el-input
                            v-if="!global.isStudent"
                            v-model="queryForm.studentNameNum"
                            maxlength="30"
                            style="width: 200px;"
                            :placeholder="$t('dispersionPracticeApply.tips.plzInputNameOrCode')"
                            prefix-icon="el-icon-search"
                            @change="handSearchChang"
                        /> -->
                    </div>
                    <div class="float-right">
                        <el-button v-if="authsBtnState.scheduleExportState" type="primary" @click="exportDialogFlag = true">
                            {{ $t('practiceReworkManagement.label.scheduleExport') }}
                        </el-button>
                        <el-button v-if="authsBtnState.exportState" type="primary" @click="handleExportSchemes">
                            {{ $t('message.export') }}
                        </el-button>
                        <el-button v-if="authsBtnState.batchReviewState" type="primary" @click="auditAll">
                            {{ $t('practiceReworkManagement.btn.auditAll') }}
                        </el-button>
                        <el-button v-if="authsBtnState.reScheduleState" type="primary" @click="reworkPanel">
                            {{ $t('practiceReworkManagement.btn.reworkPanel') }}
                        </el-button>
                        <!-- <el-button v-if="global.isAcdemicDean" type="primary" @click="publishCourse">
                            {{ $t('message.publish') }}
                        </el-button> -->
                        <!-- <el-button type="danger" @click="del('')">批量删除</el-button> -->
                        <el-button v-if="authsBtnState.addState" type="primary" @click="add('')">
                            {{ $t('message.add') }}
                        </el-button>
                    </div>
                </div>
            </el-card>
            <edu-table
                ref="tables"
                :data="data"
                :order="true"
                :orderFixed="true"
                :total="total"
                @page-change="onCurrentPageChange"
                :selectFixed='true'
            >
                <el-table-column
                    v-for="item in label"
                    :min-width="item.width"
                    :key="item.props"
                    :label="item.label"
                    :prop="item.props"
                    :sortable="item.sortable"
                    align="center"
                    show-overflow-tooltip
                    :fixed="item.fixed"
                />
                <el-table-column
                    min-width="100"
                    align="center"
                    :label="$t('courseSummary.aduitType')"
                    prop="status"
                    fixed="right"
                >
                    <template slot-scope="scope">
                        <el-tag
                            :type="fieldChange(options.tableStatus, scope.row.status, ['types','value'])"
                            class="tagClass"
                            effect="plain"
                        >{{ fieldChange(options.tableStatus, scope.row.status) }}
                        </el-tag>
                    </template>
                </el-table-column>
                <el-table-column
                    align="center"
                    width="130px"
                    :label="$t('message.operating')"
                    fixed="right"
                >
                    <template slot-scope="scope">
                        <div class="ReworkMana_btns" @click.stop>
                            <el-button
                                v-if="global.isAcdemicDean && authsBtnState.auditButState &&scope.row.status === 'ACADEMY_INPROCESS'"
                                type="text"
                                @click="open('auditFculty', scope.row.id)"
                            >{{ $t('message.check') }}
                            </el-button>
                            <el-button
                                v-if="global.isAdmin && authsBtnState.auditButState &&scope.row.status === 'SCHOOL_INPROCESS'"
                                type="text"
                                @click="open('auditSchool', scope.row.id)"
                            >{{ $t('message.check') }}
                            </el-button>
                            <el-button
                                v-if="(scope.row.status === 'DRAFT' ||scope.row.status === 'REJECTED') &&authsBtnState.editState"
                                type="text"
                                @click="add(scope.row.id)"
                            >{{ $t('message.edit') }}
                            </el-button>
                            <el-button
                                v-if="scope.row.status === 'DRAFT' && authsBtnState.deleteState"
                                type="text"
                                @click="del(scope.row.id)"
                            >{{ $t('message.delete') }}
                            </el-button>
                            <el-button v-if="authsBtnState.detailsState" type="text" @click="open('details', scope.row.id)">
                                {{ $t('message.detail') }}
                            </el-button>
                            <el-button v-if="authsBtnState.reScheduleState && scope.row.status === 'COURSE_ARRANGE'" type="text"
                                       @click="editPublishSchedule(scope.row)">
                              {{ $t('scheduleSetting.btn.edit') }}
                            </el-button>
                        </div>
                    </template>
                </el-table-column>
            </edu-table>
        </div>
        <!-- 批量审核弹框 -->
        <el-dialog
            :title="$t('dispersionPracticeApply.btn.batchCheck')"
            width="400px"
            :visible.sync="dialogFlag1"
            v-if="dialogFlag1"
            :close-on-click-modal="false"
        >
            <el-form ref="form" :model="form" label-width="100px" :rules="rules">
                <el-row>
                    <el-form-item :label="$t('practiceManagement.opinion')" props="content">
                        <el-input
                            v-model="form.content"
                            maxlength="200"
                            :rows="4"
                            :placeholder="$t('fundingManagement.tips.plzInput')"
                            type="textarea"
                            resize="none"
                        />
                    </el-form-item>
                </el-row>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="dialogFlag1 = false">{{ $t('message.cancel') }}</el-button>
                <el-button type="danger" @click="audit('reject')">
                    {{ $t('message.reject') }}
                </el-button>
                <el-button type="primary" @click="audit('pass')">
                    {{ $t('message.pass') }}
                </el-button>
            </div>
        </el-dialog>
        <!-- 新增  编辑 -->
        <el-dialog
            :visible="dialogFlag"
            :title="$t('practiceReworkManagement.title.addTitle')"
            width="926px"
            @close="dialogFlag = false"
            :close-on-click-modal="false"
        >
            <reworkAdd
                v-if="dialogFlag"
                ref="reworkAdd"
                :ids="ids"
                :yearTerm="yearTerms"
                :dialog-type="dialogType"
                :chooseFlag="chooseFlag"
                :showStuFlag="showStuFlag"
            />
            <span slot="footer" class="dialog-footer">
                <el-button @click="dialogFlag = false">{{ $t('message.cancel') }}</el-button>
                <el-button v-if="!dialogType&&(!global.isAdmin&&!global.isAcdemicDean)" type="primary" @click="sendData('save')">
                    {{ $t('message.save') }}
                </el-button>
                <el-button v-if="!dialogType" type="primary" @click="sendData('submit')">
                    {{ $t('message.submit') }}
                </el-button>
            </span>
        </el-dialog>
        <!-- 详情 学院审核 学校审核 -->
        <reworkAudit
            v-if="pathKey != 'main'&& pathKey != 'schedule' && pathKey != 'editPublishSchedule'"
            ref="reworkAudit"
            :type="pathKey"
            :ids="ids"
            @cancel="cancels"
            :dataInfo="dataInfo"
            :fromCheckDetail="fromCheckDetail"
        />
        <!--排课导出-->
        <el-dialog :title="$t('message.export')" :visible.sync="exportDialogFlag" width="400px">
            <el-form ref="forms" :model="forms" label-width="110px" :rules="exportRules">
                <!--<el-row :gutter="24">
                    <el-col>
                        <el-form-item
                            :label="$t('fundingManagement.label.courseOpenAcademy')"
                            prop="obj"
                        >
                            <el-select v-model="forms.obj" value-key="value" style="width:100%">
                                <el-option
                                    v-for="item in options.collegeId"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item"
                                ></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                </el-row>-->
                <el-row :gutter="24">
                    <el-col :span="24">
                        <el-form-item :label="$t('label.schoolTerm')" prop="yearTerm">
                            <CalendarSelect
                                v-model="forms.yearTerm"
                                style="width:100%"
                            ></CalendarSelect>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="exportDialogFlag = false">{{ $t('message.cancel') }}</el-button>
                <el-button type="primary" @click="handleExportCourse">
                    {{ $t('message.confirm') }}
                </el-button>
            </span>
        </el-dialog>
        <!-- 排课明细/ 上传 -->
        <schedule
            v-if="pathKey === 'schedule' || pathKey === 'editPublishSchedule'"
            :isEdit="isEdit"
            :objs="objs"
            @cancel="cancels"
        ></schedule>
    </div>
</template>

<script>
import { findDept } from 'common/src/api/user'
import moment from 'moment'
import commonMixins from '../commonMixins'
import schedule from './schedule'
import reworkAdd from './reworkAdd'
import reworkAudit from './reworkAudit'
import {
    getList,
    deletes,
    saveData,
    submitData,
    exportData,
    addPracticeRound,
    exportSchedule,
    publishSchedule
} from 'common/src/api/practiceManagement/practiceReworkManagement'
import { throughBatch, rejectBatch } from 'common/src/api/studentRegister'
import MyMajor from 'common/src/views/practiceManagement/common/MyMajor'
import mixin from 'common/src/mixins/index';
export default {
    // 组件名称
    name: 'PracticeReworkManagement',
    // 局部注册的组件
    components: {
        reworkAdd,
        reworkAudit,
        MyMajor,
        schedule
    },
    mixins: [commonMixins,mixin],
    // 组件参数 接收来自父组件的数据
    props: {
      dataInfo: {
        type: Object,
        default: {}
      },
      fromCheckDetail:{
        type: Boolean,
        required: false
      },
    },
    // 组件状态值
    data() {
        return {
            isEdit:false,
            dialogFlag: false,
            dialogType: false,
            dialogFlag1: false,
            exportDialogFlag: false,
            forms: {
                obj: { label: '', value: '' },
                yearTerm: ''
            },
            calendarDate:[],
            ids: '',
            yearTerms: '',
            form: {
                content: '' // 审核意见
            },
            page: {
                pageNum_: 1,
                pageSize_: 20
            },
            total: 0,
            queryForm: {
                studentNameNum: '', // 学生学号姓名
                yearTerm: '', // 学期学年
                grade: '', // 年级
                acdemyId: '', // 学院
                collegeId:'',//开课学院
                majorId: '', // 专业
                trainingLevel: 'UDG', // 培养层次
                status: '', // 状态
                courseId: '', // 课程代码
                courseName: '' // 课程名称
            },
            options: {
                compus: [],
                acdemyId: [], // 学院
                collegeId:[],//开课学院
                majorId: [], // 专业
                trainingLevel: [
                    { label: this.$t('courseConfirmation.udg'), value: 'UDG' },
                    { label: this.$t('courseConfirmation.pre'), value: 'asdf' }
                ], // 培养层次
                status: [
                    { label: this.$t('practiceManagement.status.draft'), value: 'DRAFT' },
                    { label: this.$t('practiceManagement.status.approved'), value: 'APPROVED' },
                    { label: this.$t('practiceManagement.status.rejected'), value: 'REJECTED' },
                    {
                        label: this.$t('practiceManagement.status.inFaculty'),
                        value: 'ACADEMY_INPROCESS'
                    },
                    {
                        label: this.$t('practiceManagement.status.inSchool'),
                        value: 'SCHOOL_INPROCESS'
                    },
                    { label: this.$t('practiceManagement.status.arrange'), value: 'COURSE_ARRANGE' }
                ],
                tableStatus: [
                    {
                        label: this.$t('practiceManagement.status.draft'),
                        value: 'DRAFT',
                        types: 'info'
                    },
                    {
                        label: this.$t('practiceManagement.status.inFaculty'),
                        value: 'ACADEMY_INPROCESS',
                        types: 'info'
                    },
                    {
                        label: this.$t('practiceManagement.status.inSchool'),
                        value: 'SCHOOL_INPROCESS',
                        types: 'info'
                    },
                    {
                        label: this.$t('practiceManagement.status.approved'),
                        value: 'APPROVED',
                        types: 'success'
                    },
                    {
                        label: this.$t('practiceManagement.status.rejected'),
                        value: 'REJECTED',
                        types: 'danger'
                    },
                    {
                        label: this.$t('practiceManagement.status.arrange'),
                        value: 'COURSE_ARRANGE',
                        types: 'success'
                    }
                ]
            },
            data: [],
            label: [
                { label: this.$t('label.stuCode'), props: 'studentNo', width: 90, sortable: true, fixed: 'left' },
                {
                    label: this.$t('label.stuName'),
                    props: 'studentName',
                    width: 90,
                    sortable: true,
                    fixed: 'left'
                },
                {
                    label: this.$t('fundingManagement.label.courseOpenAcademy'),
                    props: 'collegeName',
                    width: 180,
                    sortable: true
                },
                {
                    label: this.$t('courseConfirmation.label.stuFaculty'),
                    props: 'acdemyName',
                    width: 180,
                    sortable: true
                },
                { label: this.$t('label.grade'), props: 'grade', width: 100, sortable: true },
                { label: this.$t('label.major'), props: 'majorName', width: 180, sortable: true },
                {
                    label: this.$t('fundingManagement.label.courseProgramNumber'),
                    props: 'subCourseId',
                    width: 100,
                    sortable: true
                },
                {
                    label: this.$t('fundingManagement.label.courseCode'),
                    props: 'courseId',
                    width: 100,
                    sortable: true
                },
                {
                    label: this.$t('practiceReworkManagement.label.applyCourse'),
                    props: 'courseName',
                    width: 100,
                    sortable: true
                },
                {
                    label: this.$t('practiceReworkManagement.label.applyReason'),
                    props: 'applyReason',
                    width: 100,
                    sortable: true
                },
                {
                    label: this.$t('practiceReworkManagement.label.files'),
                    props: 'attachName',
                    width: 180,
                    sortable: true
                }
            ],
            pathKey:this.$route.query.pathKey?this.$route.query.pathKey:'main',
            //pathKey: 'main',
            path: {
                label: this.$t('practiceReworkManagement.title.pathTitle'),
                key: 'main',
                disable: false,
                children: [
                    { label: this.$t('message.detail'), key: 'details', disable: true },
                    {
                        label: this.$t('practiceManagement.status.inFaculty'),
                        key: 'auditFculty',
                        disable: true
                    },
                    {
                        label: this.$t('practiceManagement.status.inSchool'),
                        key: 'auditSchool',
                        disable: true
                    },
                    {
                        label: this.$t('practiceManagement.title.arrangeCourse'),
                        key: 'schedule',
                        disable: true
                    },
                    {
                        label: this.$t('scheduleSetting.path.childrenLabel7'),
                        key: 'editPublishSchedule',
                        disable: true
                    }
                ]
            },
            rules: {},
            exportRules: {
                obj: {
                    required: true,
                    validator: this.validateSurnmae,
                    trigger: ['change']
                },
                yearTerm: {
                    required: true,
                    message: this.$t('practiceReworkManagement.tips.mustWrite'),
                    trigger: ['change']
                }
            },
            objs: {
                courseName: '',
                num:'',
                courseNumber:'',
                courseOpenAcademyId:'',
                ids:''
            },
            auths: [],
            authsBtnState: {
              addState: false, // 新增
              editState: false, // 编辑
              deleteState: false,   // 删除
              auditButState: false,   // 审核
              exportState: false, // 导出
              detailsState: false, // 详情
              batchReviewState: false, // 批量审核
              reScheduleState: false, // 重修排课
              scheduleExportState: false, // 排课导出
            },
            chooseFlag:false,
            showStuFlag:false
        }
    },
    // 计算属性
    computed: {
        colorTypes() {
            // 状态颜色
            return function(val) {
                let type = ''
                if (val === 'REJECTED') {
                    type = 'success'
                } else if (val === 'COURSE_ARRANGE') {
                    type = 'danger'
                }
                return type
            }
        }
    },
    // 侦听器
    watch: {
      auths: {
        handler(newVal) {
          if (newVal && Array.isArray(newVal) && newVal.length > 0) {
            newVal.some(item => {
              // 新增
              if (item.authCode === 'practiceReworkManagement-add') {
                this.authsBtnState.addState = true;
              }
              // 编辑
              if (item.authCode === 'practiceReworkManagement-edit') {
                this.authsBtnState.editState = true;
              }
              // 删除
              if (item.authCode === 'practiceReworkManagement-delete') {
                this.authsBtnState.deleteState = true;
              }
              // 审核
              if (item.authCode === 'practiceReworkManagement-auditBut') {
                this.authsBtnState.auditButState = true;
              }
              // 导出
              if (item.authCode === 'practiceReworkManagement-export') {
                this.authsBtnState.exportState = true;
              }
              // 详情
              if (item.authCode === 'practiceReworkManagement-details') {
                this.authsBtnState.detailsState = true;
              }
              // 批量审核
              if (item.authCode === 'practiceReworkManagement-batchReview') {
                this.authsBtnState.batchReviewState = true;
              }
              // 重修排课
              if (item.authCode === 'practiceReworkManagement-reSchedule') {
                this.authsBtnState.reScheduleState = true;
              }
              // 排课导出
              if (item.authCode === 'practiceReworkManagement-scheduleExport') {
                this.authsBtnState.scheduleExportState = true;
              }
            });
          }
        }
      }
    },
    /**
     * 在实例初始化之后，组件属性计算之前，如data属性等
     */
    created() {
      // 获取当前用户auths权限
      if (localStorage.getItem("sessiondata")) {
        if (JSON.parse(localStorage.getItem("sessiondata")).auths) {
          this.auths = JSON.parse(localStorage.getItem("sessiondata")).auths;
        }
      }
    },
    /**
     * 在挂载开始之前被调用：相关的 render 函数首次被调用。
     */
    mounted() {
        let param = {
            X_YX: 'collegeId', // 学院
            X_XQ: 'compus'
        }
        this.initOptions(param)
        findDept(0).then(res => {
            if (res.code == 200 && res.data) {
                this.options.acdemyId = res.data.map(row => {
                    return { label: row.deptName, value: row.deptCode }
                })
            }
        })
    },
    // 组件方法
    methods: {
        validateSurnmae(rule, value, callback) {
            if (!this.forms.obj.label && this.forms.obj.label === '') {
                return callback(new Error(this.$t('fundingManagement.tips.plzInput')))
            } else {
                return callback()
            }
        },
        reworkPanel() {
            // 批量重修排课
            let selection = this.$refs.tables.selectionDatas
            if (!selection || selection.length === 0) {
                this.$noSelectAlert()
                return
            }
            let count = 0
            let count2 = 0
            let ids = []
            let firstData = selection[0]
            selection.forEach(t => {
                ids.push(t.id)
                if (t.status !== 'APPROVED') {
                    count++
                    return
                }
                // //判断同一学院
                // if (t.acdemyId !== firstData.acdemyId) {
                //     count2++
                //     return
                // }
                //判断同一课程
                if (t.courseId !== firstData.courseId) {
                    count2++
                    return
                }
            })
            if (count > 0) {
                this.$message({
                    message: this.$t('practiceReworkManagement.tips.batchPractice'),
                    type: 'warning'
                })
                return
            }
            if (count2 > 0) {
                this.$message({
                    message: this.$t('practiceReworkManagement.tips.batchPractice2'),
                    type: 'warning'
                })
                return
            }
            this.reworkBtns(this.yearTerms).then(res => {
                if (res) {
                    let id = selection.map(item => {
                        return { id: item.id }
                    })
                    this.objs.num = selection.length
                    this.objs.courseName = firstData.courseName
                    this.objs.courseNumber = firstData.courseId
                    this.objs.courseOpenAcademyId = firstData.acdemyId
                    this.objs.ids = ids
                    this.pathKey = 'schedule'
                }
            })
        },
        auditAll() {
            // 批量审核
            let selection = this.$refs.tables.selectionDatas
            if (!selection || selection.length === 0) {
                this.$noSelectAlert()
                return
            }
            let count = 0
            selection.forEach(t => {
                if (this.global.isAcdemicDean && t.status !== 'ACADEMY_INPROCESS') {
                    count++
                }
                if (this.global.isAdmin && t.status !== 'SCHOOL_INPROCESS') {
                    count++
                }
            })
            if (count > 0) {
                this.$message({
                    message: this.$t('practiceReworkManagement.tips.batchAuditTip'),
                    type: 'warning'
                })
                return
            }
            this.dialogFlag1 = true
            this.form.content = ''
        },
        audit(type) {
            // 批量审核
            let selection = this.$refs.tables.selectionDatas
            let data = selection.map(r => {
                return {
                    no: r.workFlowId,
                    content: this.form.content
                }
            })
            if (type === 'pass') {
                // 通过
                this.$refs.form.validate(valid => {
                    if (valid) {
                        throughBatch(data).then(res => {
                            if (res && res.code !== 200) {
                                this.$message({ message: res.msg, type: 'warning' })
                                return
                            }
                            this.getLists(true)
                            this.dialogFlag1 = false
                        })
                    }
                })
            } else {
                // 驳回
                if (!this.form.content) {
                    this.$message({
                        message: this.$t('dispersionPracticeApply.tips.rejectContent'),
                        type: 'warning'
                    })
                } else {
                    rejectBatch(data).then(res => {
                        if (res && res.code !== 200) {
                            this.$message({ message: res.msg, type: 'warning' })
                            return
                        }
                        this.getLists(true)
                        this.dialogFlag1 = false
                    })
                }
            }
        },
        sendData(val) {
            // 保存， 提交
            let data = this.$refs.reworkAdd.getData(val)
            if (val === 'save') {
                this.$set(data, 'yearTerm', this.yearTerms)
                saveData(data).then(res => {
                    // 保存
                    if (res && res.code !== 200) {
                        this.$message({ message: res.msg, type: 'warning' })
                        return
                    }
                    this.getLists(true)
                    this.$message({ message: this.$t('message.saveSuccess'), type: 'success' })
                    this.dialogFlag = false
                })
            } else if (val === 'submit' && data) {
                this.$set(data, 'yearTerm', this.yearTerms)
                submitData(data).then(res => {
                    // 提交
                    if (res && res.code !== 200) {
                        this.$message({ message: res.msg, type: 'warning' })
                        return
                    }
                    this.getLists(true)
                    this.$message({ message: this.$t('message.submitSuccess'), type: 'success' })
                    this.dialogFlag = false
                })
            }
        },
        handSearchChang() {
            // 搜索
            this.getLists(true)
        },
        reset() {
            // 重置
            for (const key in this.queryForm) {
                if (key !== 'yearTerm') {
                    this.queryForm[key] = ''
                }
            }
            this.queryForm.yearTerm = this.yearTerms
            this.queryForm.trainingLevel = 'UDG'
            this.getLists(true)
        },
        onSubmit() {
            // 筛选
            this.getLists(true)
        },
        getLists(refresh) {
            if (refresh) {
                this.page.pageNum_ = 1;
                if(this.$refs.tables) {
                  this.$refs.tables.pageNum = 1;
                }
            }
            // 获取列表
            let jsons = {
                condition: this.queryForm,
                pageNum_: this.page.pageNum_,
                pageSize_: this.page.pageSize_
            }
            getList(jsons).then(res => {
                this.data = res.data.list
                this.total = res.data.total_
                this.data.forEach(item => {
                    let attachName = ''
                    if (item.udgPtAttachTs.length > 0) {
                        attachName = item.udgPtAttachTs[0].attachName
                    }
                    this.$set(item, 'attachName', attachName)
                    this.$set(item, 'statuss', this.fieldChange(this.options.status, item.status))
                })
            })
        },
        add(val) {
            // 添加， 编辑
            this.ids = val
            this.dialogFlag = true
            if(this.global.isAdmin || this.global.isAcdemicDean){
                this.showStuFlag = true;
            }else{
                this.showStuFlag = false;
            }
            this.chooseFlag = true;
            if(val){
                this.showStuFlag = false;
                this.chooseFlag = false;
            }
        },
        del(id) {
            // 删除
            let jsonData = []
            if (!id) {
                // 批量删除
                let selection = this.$refs.tables.selectionDatas
                if (!selection || selection.length === 0) {
                    this.$noSelectAlert()
                    return
                }
                let flag = false
                selection.forEach(item => {
                    if (item.status !== 'DRAFT') {
                        flag = true
                        return
                    } else {
                        jsonData.push({ id: item.id })
                    }
                })
                if (flag) {
                    this.$message({
                        message: this.$t('dispersionPracticeApply.tips.statusWrong'),
                        type: 'warning'
                    })
                    return
                }
            } else {
                jsonData.push({ id: id })
            }
            this.$confirm(this.$t('message.areYouSureDelete'), this.$t('message.prompt'), {
                confirmButtonText: this.$t('message.confirm'),
                cancelButtonText: this.$t('message.cancel'),
                type: 'warning'
            }).then(() => {
                deletes(jsonData).then(res => {
                    if (res && res.code !== 200) {
                        this.$message({ message: res.msg, type: 'warning' })
                        return
                    }
                    this.getLists(true)
                    this.$message({ type: 'success', message: this.$t('message.deleteSuccess') })
                })
            })
        },
        editPublishSchedule(row){
            this.isEdit = true
            this.objs.num = 1
            this.objs.courseName = row.courseName
            this.objs.courseNumber = row.courseId
            this.objs.courseOpenAcademyId = row.acdemyId
            this.objs.ids = [row.id]
            this.objs.id = row.id
            this.pathKey = 'editPublishSchedule'
        },
        open(val, ids) {
            // 跳转
            this.isEdit = false
            this.pathKey = val
            this.ids = ids
        },
        cancels(val) {
            // 退出
            if (val === 'refresh') {
                this.getLists(true)
            }
            this.pathKey = 'main'
        },
        onCurrentPageChange(val) {
            // 分页事件
            ;[this.page.pageNum_, this.page.pageSize_] = [val.pageNum, val.pageSize]
            this.getLists()
        },
        loadDone(data) {
            this.yearTerms = this.queryForm.yearTerm
            this.calendarDate = data;
            this.getLists()
        },
        handleExportSchemes(type) {
            // 导出
            let selection = this.$refs.tables.selectionDatas
            let params = {
                exportType: 0,
                request: this.queryForm,
                responses: selection
            }
            if (selection && selection.length > 0) {
                params.exportType = 1
                params.responses = selection.map(item => {
                    return { id: item.id }
                })
            }
            exportData(params)
        },
        handleExportCourse() {
            this.$refs.forms.validate(valid => {
                if (valid) {
                    let params = {
                        yearTerm: this.forms.yearTerm,
                        acdemyId: this.forms.obj.value
                    }
                    let schoolTerm = this.calendarDate.find(v => {
                        return v.id === params.yearTerm
                    })
                    params.acdemyId = ''
                    exportSchedule(params, this.forms.obj.label + '-' + schoolTerm.fullName)
                    this.exportDialogFlag = false
                }
            })
        },
        // publishCourse(){
        //     this.$confirm(this.$t('practiceReworkManagement.tips.publishTips'), this.$t('message.prompt'), {
        //         confirmButtonText: this.$t('message.confirm'),
        //         cancelButtonText: this.$t('message.cancel'),
        //         type: 'warning'
        //     }).then(() => {
        //         publishSchedule().then(res => {
        //             if (res && res.code !== 200) {
        //                 this.$message({ message: res.msg, type: 'warning' })
        //                 return
        //             }
        //             this.getLists(true)
        //             this.$message({ type: 'success', message: this.$t('scheduleSetting.tips.publishSuccess') })
        //         })
        //     })
        // }
    }
}
</script>
<style lang="scss" scoped>
.ReworkMana {
    &_btns {
        display: flex;
    }
}
.titles {
    font-weight: bold;
    color: #2b3b4e;
}
</style>
